from typing import List
from collections import defaultdict
class Solution:
    def subarraySum(self, nums: List[int], k: int) -> int:
        ans = s = 0
        cnt = defaultdict(int)
        print("cnt=",cnt)
        for x in nums:
            cnt[s]+=1
            print("==",cnt)
            s+=x
            ans+=cnt[s-k]
            print("ans= ",ans,(s-k),cnt)
            print("=========")
        return ans

# print(Solution().subarraySum([1,1,1],2))
# nums = [1,1,1,1]
# print(Solution().subarraySum(nums,2))
nums = [1,1,1]
count = 0
for start in range(len(nums)):
    sum = 0
    for end in range(start,-1,-1):
        sum += nums[end]
        if sum == 2:
            count += 1
print(count)
